# -*- coding: utf-8 -*-
# @File : .py
# @Author : ZhouHang
# @Date : 18-8-26
# @Desc :
from flask import redirect
from flask import  Blueprint

admin_blu = Blueprint('admin', __name__, url_prefix="/admin")

from .views import *

@admin_blu.before_request
def before_request():
    """
    对每次请求管理员界面的非主页都做权限验证
    :return:
    """
    if not request.url.endswith(url_for("admin.admin_login")):
        user_id = session.get("user_id", None)
        is_admin = session.get("is_admin", False)
        if not user_id or not is_admin:
            return redirect("/")
